<template>
    <div class="order-item-box">
        <el-row class="border-none">
            <el-col :span="6"><div class="left-text"> Ref No.: {{item.sn}}({{item.order_from === 1 ? 'Online' : 'Public'}})</div></el-col>
            <el-col :span="18" style=" text-align: right;">
             

                <div class="rig-button-box">
                   <el-popover
                        placement="bottom"
                        width="300"
                        v-model="isShow">
                        <div class="email-box">
                            <div class="hd">Select E-mail Type</div>
                            <div>
                                <el-checkbox-group 
                                    v-model="etype"
                                    :min="1"
                                    :max="1">
                                    <el-checkbox label="1">Public/workshop/Event with price</el-checkbox>
                                    <el-checkbox label="2">Public/workshop/Event without price</el-checkbox>
                                    <el-checkbox label="3">Online with price</el-checkbox>
                                    <el-checkbox label="4">Online without price</el-checkbox>
                                </el-checkbox-group>
                                <div class="mail-btn-box">
                                    <el-button size="mini" @click="onSendCancel()"  >cancel</el-button>
                                    <el-button type="warning" @click="onSend(item)" size="mini" >Send</el-button>
                                </div>
                            </div>
                        </div>
                        <el-button slot="reference" class="filter-item" size="mini" type="warning" icon="el-icon-edit">E-mail</el-button>
                    </el-popover>
                    <!-- <span class="button-item" ><el-button class="filter-item" style="margin-left: 10px;"  size="mini" type="warning" icon="el-icon-edit">E-mail</el-button>
                    <div class="email-box">
                        <div class="hd">Select E-mail Type</div>
                        <div>
                            <el-checkbox-group 
                                v-model="mailCheck"
                                :min="1"
                                :max="2">
                                <el-checkbox label="Public/workshop/Event with price" :key="0">Public/workshop/Event with price</el-checkbox>
                                <el-checkbox label="Public/workshop/Event without price" :key="1">Public/workshop/Event without price</el-checkbox>
                                <el-checkbox label="Online with price" :key="2">Online with price</el-checkbox>
                                <el-checkbox label="Online without price" :key="3">Online without price</el-checkbox>
                            </el-checkbox-group>
                            <div>
                                <el-button size="mini" >cancel</el-button>
                                <el-button type="warning" @click="onSend" size="mini" >Send</el-button>
                            </div>
                        </div>
                    </div></span> -->
                    <el-button class="filter-item" style="margin-left: 10px;"  size="mini" type="primary" icon="el-icon-edit" @click="onDuplicate(item)">Duplicate</el-button>
                    <el-button class="filter-item" style="margin-left: 10px;"  size="mini" type="success" icon="el-icon-edit" @click="updateOrderHold(item.id)">Resume</el-button>
                    <el-button class="filter-item" style="margin-left: 10px;"  size="mini" type="primary" icon="el-icon-edit" @click="updateOrderResume(item.id)">Hold</el-button>
                    <el-button class="filter-item" style="margin-left: 10px;"  size="mini" type="danger" icon="el-icon-edit" @click="updateOrderVoid(item.id)">Void</el-button>
                </div>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="3"><div class="grid-content bg-grey-light">Date In </div></el-col><el-col :span="3"><div class="grid-content">{{item.order_date_in}}</div></el-col>
            <el-col :span="3"><div class="grid-content bg-grey-light">Payment Status</div></el-col><el-col :span="3"><div class="grid-content">{{item.trade_no ? 'PAID' : 'UNPAID'}}</div></el-col>
            <el-col :span="3"><div class="grid-content bg-grey-light">Status</div></el-col><el-col :span="3"><div class="grid-content"> <i class="el-icon-check f-green" v-if="item.status"></i><i class="el-icon-close f-red" v-if="!item.status"></i></div></el-col>
            <el-col :span="3"><div class="grid-content bg-grey-light">Created By</div></el-col><el-col :span="3"><div class="grid-content"> </div></el-col>

            <el-col :span="3"><div class="grid-content bg-grey-light">Name</div></el-col><el-col :span="3"><div class="grid-content">{{item.fristname}}{{item.lastname}}</div></el-col>
            <el-col :span="3"><div class="grid-content bg-grey-light">E-mail</div></el-col><el-col :span="3"><div class="grid-content">{{item.email}} </div></el-col>
            <el-col :span="3"><div class="grid-content bg-grey-light">Contact No.</div></el-col><el-col :span="3"><div class="grid-content">{{item.mobile}} </div></el-col>
            <el-col :span="3"><div class="grid-content bg-grey-light">CardHolder No.</div></el-col><el-col :span="3"><div class="grid-content">{{item.cardholder_numer}}</div></el-col>

            <el-col :span="3"><div class="grid-content bg-grey-light">Aliergies</div></el-col><el-col :span="6"><div class="grid-content">{{item.allergie ? 'Yes' : 'No'}}</div></el-col>
            <el-col :span="3"><div class="grid-content bg-grey-light">Remark</div></el-col>
            <el-col :span="12">
                <div class="grid-content">
                    <div style=" position: absolute; width: 420px;"> 
                        <el-input
                            type="textarea"
                            :rows="2"
                            :placeholder="$t('placeholder.input')"
                            v-model="item.remark"
                            style="width:400px"
                            @blur="updateOrderRemark(index)">
                            </el-input> <i class="el-icon-edit"></i>
                    </div>
                </div>
            </el-col>

            <el-col :span="3"><div class="grid-content bg-grey-light">Juice Before</div></el-col><el-col :span="21"><div class="grid-content">{{item.juice_cleanse_before ? 'Yes' : 'No'}}</div></el-col>
            
            <!-- <el-col :span="8">
                <div class="grid-content bg-grey-light center">Package</div>
            </el-col>
            <el-col :span="6">
                <div class="grid-content bg-grey-light center">Localtion</div>
            </el-col>
            <el-col :span="3"><div class="grid-content bg-grey-light center">Delivery Date</div></el-col>
            <el-col :span="3"><div class="grid-content bg-grey-light center">AX Status</div></el-col>
            <el-col :span="4"><div class="grid-content bg-grey-light center">Collected Date Confirm</div></el-col>
            <el-col :span="24" v-for="(group, t) in item.group" :key="t" style="margin-bottom:0" class="order-group-products">
                <order-product :item="item" :group="group" :idx="t" :location-options="locationOptions"></order-product>
            </el-col> -->
            <el-col :span="3"><div class="grid-content bg-grey-light">Payment</div></el-col>
            <el-col :span="7"><div class="grid-content">
                <div class="payment-box" v-for="(pay, t) in item.payment" :key="t">
                    <span class="item">- {{pay.payment_method === 1 ? 'WeiXin' : pay.payment_method === 2 ? 'ZhiFuBao' : 'PayPal'}}</span> 
                    <span class="item">{{lang === 'en' ? '$' : '￥'}}{{pay.amount}}</span>
                </div>
            </div></el-col>
            <el-col :span="14"><div class="grid-content">Remark:  <span v-if="!isEditPayRemark">{{ item.paymentRemark }}</span><i class="el-icon-edit"  @click="isEditPayRemark = !isEditPayRemark"></i>
                <div v-if="isEditPayRemark">
                    <el-input
                        type="textarea"
                        :rows="2"
                        :placeholder="$t('placeholder.input')"
                        v-model="item.paymentRemark"
                        style="width:400px"
                        @blur="updateOrderPaymentRemark(index)">
                    </el-input> 
                </div>
            </div></el-col>

            <el-col :span="15"><div class="grid-content bg-purple">Total Delivery Charge：$0.00</div></el-col><el-col :span="6"><div class="grid-content">Total Amount：{{lang === 'en' ? '$' : '￥'}}{{item.tprice}}</div></el-col>
            <el-col :span="3"><div class="grid-content">Total Paid：$1,150.00</div></el-col>
            <el-col :span="24">
                <div class="grid-content text-center"> <el-button class="filter-item" style="margin-left: 10px;" type="text"  @click="toDetail(itemData)">Detail</el-button></div>
            </el-col>
        </el-row>
    </div>
</template>
<script>
import { fetchUpdateRemark, fetchUpdatePaymentRemark, fetchHold, fetchResume, fetchOrderVoid, fetchOrderEmail } from '@/api/order'
import i18n from '@/lang/index'
export default {
    props: {
        list: Array,
        itemData: Object
    },
    data() {
        return {
            lang: i18n.locale,
            etype: [],
            item: this.itemData,
            isEditPayRemark: false,
            isShow: false
        }
    },
    methods: {
        updateOrderRemark(index) {// 修改订单备注
            if (this.item.remark) {
                let data = {
                    id: this.item.id,
                    remark: this.item.remark
                }
                fetchUpdateRemark(this.item.id, data).then(() => {
                    this.$notify({
                        title: 'Success​',
                        message: 'Update Success!​',
                        type: 'success',
                        duration: 2000
                    })
                })
            }
            
        },
        updateOrderPaymentRemark(index) {// 修改订单备注
            if (this.item.paymentRemark) {
                let data = {
                    id: this.item.id,
                    remark: this.item.paymentRemark
                }
                fetchUpdatePaymentRemark(this.item.id, data).then(() => {
                    this.$notify({
                        title: 'Success​',
                        message: 'Update Success!​',
                        type: 'success',
                        duration: 2000
                    })
                })
            }
            
        },
        onDuplicate(item) {// 添加新订单
            this.$emit('on-duplicate', item)
        },
        updateOrderHold(id) {// 暂停订单
            fetchHold(id).then(() => {
                this.$notify({
                    title: 'Success​',
                    message: 'Update Success!​',
                    type: 'success',
                    duration: 2000
                })
            })
        },
        updateOrderResume(id) {// 继续订单
            fetchResume(id).then(() => {
                this.$notify({
                    title: 'Success​',
                    message: 'Update Success!​',
                    type: 'success',
                    duration: 2000
                })
            })
        },
        updateOrderVoid(id) {// 无效订单
            fetchOrderVoid(id).then(() => {
                this.$notify({
                    title: 'Success​',
                    message: 'Update Success!​',
                    type: 'success',
                    duration: 2000
                })
            })
        },
        toDetail(item) {
            this.$emit('to-detail', item)
        },
        onSendCancel() {
            this.etype = []
            this.isShow = false
        },
        onSend(item) {
            let _this = this
            let params = {
                id: item.id,
                etype: this.etype.join()
            }
            if (this.etype) {
                fetchOrderEmail(item.id, params).then(() => {
                    _this.etype = []
                    _this.$notify({
                        title: 'Success​',
                        message: 'Update Success!​',
                        type: 'success',
                        duration: 2000
                    })
                    _this.isShow = false
                })
            }
        }
    }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.order-item-box{ 
    border: 1px solid #ccc;
    padding: 15px;
    margin-bottom: 15px;
    .border-none.el-row{ border:none;}
    .el-form-item{ margin-bottom: 0;}
    .el-row {
        margin-bottom: 20px;
        border-bottom: 1px solid #e5e9f2;
        border-right: 1px solid #e5e9f2;
        /* &:last-child {
            margin-bottom: 0;
        } */
    }
    .left-text {
        line-height: 30px;
    }
    .grid-content {
        padding: 5px;
        line-height: 20px;
        min-height: 36px;    
        border-left: 1px solid #e5e9f2;
        border-top: 1px solid #e5e9f2;
    }
    .bg-grey-light{ text-align: right; background: #e5e9f2;}
    .center{ text-align: center;}
    .f-red{ color: #f00;}
    .f-green{ color: #67C23A;}
}
.email-box{
    width: 280px; 
    text-align: left;
    background: #fff;
    line-height: 30px;
    font-size: 12px;
    .hd{
        font-weight: bold;
        border-bottom: 1px solid #eee;
    }
    label{ display: block;}
    .el-checkbox{
        margin-left: 10px;
    }
    .el-checkbox__label{
        font-size: 12px;
    }
    .mail-btn-box{
        text-align: right;
    }
}
</style>
